﻿using IFRS.DataAccess.DAL;
using IFRS.Models;
using IFRS.Web;
using IFRS_Global;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Threading;
using System.Web.UI;

public partial class IFRS_WIN16_3V : PageBase
{
    #region "---------- Events -----------"

    protected void Page_Load(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        if (!(Page.IsPostBack || Page.IsCallback))
        {
            ViewMenu();
            BindDDL();
            if (Request.QueryString["id"] != null)
            {
                this.BindData(Convert.ToInt32(Request.QueryString["id"].ToString()));
            }
            SetControl();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }

    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN16_1S.aspx");
    }   
    #endregion "---------- Events -----------"

    #region "----------  Methods -----------"
 
    private void ViewMenu()
    {
        MenuTitleBar = Resources.ifrsMenu.WIN01_4A;
    }  

    private void BindData(int ID)
    {
        List<CounterParty> counterParty = new List<CounterParty>();
        DataTable dt = new SPR_COUNTERPARTY().SEARCH_BYID(ID);
        if (dt.Rows.Count > 0)
        {
            ConvertHelper.ConvertDataTableToObject(dt, counterParty);
            txtTransactionDate.Text = counterParty[0].TransactionDate.DateToString();
            txtCounterPartyName.Text = counterParty[0].CounterPartyName;
            txtFinancialNameTH.Text = counterParty[0].FinancialNameTH;
            txtFinancialNameEN.Text = counterParty[0].FinancialNameEN;
            ddlFinancialType.SelectedValue = counterParty[0].FinancialTypeID.IntToString();
            ddlPartyType.SelectedValue = counterParty[0].PartyTypeID.IntToString();
            txtGLAccountBondAdd.Text = counterParty[0].GLAccountBondAdd;
            txtGLAccountBondMinus.Text = counterParty[0].GLAccountBondMinus;
        }
    }

    private void SetControl()
    {
        SetControlReadOnly(form_control);
    }

    private void BindDDL()
    {
        ddlFinancialType.SetData(DDL_TYPE.FinancialType, "", false, true);
        ddlPartyType.SetData(DDL_TYPE.PartyType, "", false, true);
    }
    #endregion "---------- Methods -----------"
}